import socket

s_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = ('localhost', 8082)  # 更改为8082端口
s_socket.bind(address)
s_socket.listen(5)
print("服务器正在监听 8082 端口...")

while True:
    c_socket, c_address = s_socket.accept()
    print("接收到来自 {} 的连接".format(c_address))
    try:
        while True:
            data = c_socket.recv(1024)
            if not data:
                break
            print("客户端说: {}".format(data.decode('utf-8')))
            c_socket.send("你好".encode())
    finally:
        c_socket.close()